﻿@*角色编辑页面*@

@{
    Layout = "_Layout";
    string id = (string)ViewData["id"];
}
<div style="margin: 15px;">
    <form class="layui-form" id="updateForm" action="@Url.Action("Edit","Role")">
        <div class="layui-form-item">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-block">
                <input type="text" name="code"  data-bind="value: code" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" class="layui-input" data-bind="value:name">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remarks" class="layui-textarea" data-bind="value:remarks"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="btnSubmit">提交</button>
            </div>
        </div>
    </form>
    <script type="text/javascript">
        function vModel() {
            this.id = ko.observable("");
            this.code = ko.observable("");
            this.name = ko.observable("");
            this.remarks = ko.observable("");
        }
        var model = new vModel();
        layui.use(['element',  'form'], function () {
            var $ = layui.jquery,
                form = layui.form;
            $.ajax({
                type: "Get",
                url: "/Role/Get?id=" + '@id', //获取数据的ajax请求地址
                success: function (res) {
                    if (res.success) {
                        ko.mapping.fromJS(res.data, {}, model);
                        form.render();
                    } else {
                        admin_error(res.msg);
                    }
                }
            });


            //监听提交
            form.on('submit(btnSubmit)', function (data) {
                $.ajax({
                    url: $("#updateForm").attr("action"),
                    type: 'post',
                    dataType: 'json',
                    async: false,
                    data: model,//$("#updateForm").serialize(),
                    success: function (res) {
                        if (res.success) {
                            admin_success();
                            parent.layer.closeAll('iframe');
                        } else {
                            admin_error(res.msg);
                        }
                    }
                });
                return false;
            });
        });
        ko.applyBindings(model);//注册vModel
    </script>
</div>